package com.cat.dataStructure02;

/**
 *   @description https://leetcode.cn/problems/lexicographically-smallest-string-after-operations-with-constraint/description/
 *   @author 曲大人的喵
 *   @create 2025/10/19 17:44
 *   @since JDK17
 */

public class Solution24 {
    int get(char a) {
        return Math.min(a - 'a', 'z' + 1 - a);
    }
    public String getSmallestString(String str, int k) {
        char[] s = str.toCharArray();
        int n = s.length;
        for (int i = 0; i < n; i++) {
            int cost = get(s[i]);
            if (k >= cost) {
                s[i] = 'a';
                k -= cost;
            } else {
                s[i] -= k;
                break;
            }
        }

        return new String(s);
    }
}
